<?php


namespace app\user\controller;


use think\Controller;
use think\Db;
use think\Session;

class Index extends Base
{

    public function Index(){
//        //轮播
//        $banner = Db::name('banner')->select();
        //简介
//        $Config = Config();
//        //记录
//        $record = Db::name('user_deposit')->where(['user_id'=>$this->user_id])->select();
//
//        //最新公告
//        $notice = Db::name('notice')->order('id desc')->limit(4)->select();
//        //累计静态
//        $reward1 = Db::name('finance')->where(['user_id'=>$this->user_id,'reward_type'=>13])->sum('num');
//        //累计动态
//        $reward2 = Db::name('finance')->where(['user_id'=>$this->user_id,'reward_type'=>14])->sum('num');
//        //累计手数佣金
//        $reward3 = Db::name('finance')->where(['user_id'=>$this->user_id,'reward_type'=>15])->sum('num');
//        //团队动态手数
//        $reward4 = Db::name('finance')->where(['user_id'=>$this->user_id,'reward_type'=>16])->sum('num');
//        $UserInfo = UserInfo(['id'=>$this->user_id]);
//        $withdraw = Db::name('user_withdraw')->where(['user_id'=>$this->user_id,'status'=>1])->sum('num');
//        $LevelInfo = LevelInfo(['id'=>$UserInfo['level']]);
        $init = Session::get('init_flag');
        if ($init == 1){
            $flag = true;
            Session::set('init_flag',0);
        }else{
            $flag = false;
        }
        $this->assign([
            'flag'=>$flag
//            'banner'=>$banner,
//            'record'=>$record,
//            'config'=>$Config,
//            'notice'=>$notice,
//            'reward1'=>$reward1,
//            'reward2'=>$reward2,
//            'reward3'=>$reward3,
//            'reward4'=>$reward4,
//            'UserInfo'=>$UserInfo,
//            'withdraw'=>$withdraw,
//            'LevelInfo'=>$LevelInfo,
        ]);
        return $this->fetch('Index');
    }

    public function Index2(){
        $Config = Config();
        $this->assign([
            'config'=>$Config,
        ]);
        return $this->fetch('Index3');
    }
    

    public function bill(){

        return $this->fetch('bill');
    }

    public function getMore(){
        $page = Param('page');
        $goods_list = Db::name('goods_mall')->where(['is_shelf'=>2])->page($page,2)->select();
        $goods_class = Db::name('goods_class')->select();
        $arr = array_count_values(array_column($goods_list,'parent_id'));
        foreach ($goods_class as $k=>$v){
            if (isset($arr[$v['id']])){
                $goods_class[$k]['count'] = $arr[$v['id']];
            }else{
                $goods_class[$k]['count'] = 0;
            }
        }
        $res['goods'] = $goods_list;
        $res['goods_class'] = $goods_class;
        $res['all'] = array_sum(array_column($goods_class,'count'));
        return ReturnMsg(1,'',$res);
    }

    public function Map(){

        return $this->fetch('Map');
    }
}